package b1.controls.basic
{
	import b1.net.*;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.text.*;
	
	public class MessageBox extends Sprite
	{
		public var buttonOK:BasicButton;
		public var buttonCacel:BasicButton;
		
		public function MessageBox(message:String, alpha:Number = 1, hasCacelButton:Boolean = false)
		{
			super();
			var MessageBoxGgr:Class = ResourceHelper.getInstance().getClassByName("MessageBox1");
			var mainSprite:Sprite = new MessageBoxGgr();
			mainSprite.alpha = alpha;
			addChild(mainSprite);

			//信息文字
			var messageText:TextField = new TextField();
			messageText.selectable = false;
        	messageText.autoSize = TextFieldAutoSize.CENTER;
			messageText.defaultTextFormat = new TextFormat("微软雅黑", 15, 0x000000);;
			messageText.text = message;
			messageText.x = (mainSprite.width - messageText.width) / 2;
			messageText.y = mainSprite.height / 2 - messageText.height;
			addChild(messageText);
			
			//确定按钮
			var ButtonBgr:Class = ResourceHelper.getInstance().getClassByName("ButtonBgr1");
			buttonOK = new BasicButton(ButtonBgr, "确定");
			if (!hasCacelButton)
			{
				buttonOK.x = (mainSprite.width  - buttonOK.width) / 2;
			}
			else
			{
				buttonOK.x = mainSprite.width / 2 - buttonOK.width - 10;
			}
			buttonOK.y = mainSprite.height - buttonOK.height - 60;
			buttonOK.addEventListener(MouseEvent.CLICK, onButtonOKClick);
			addChild(buttonOK);
			if (hasCacelButton)
			{
				buttonCacel = new BasicButton(ButtonBgr, "取消");
				buttonCacel.x = mainSprite.width / 2 + 10;
				buttonCacel.y = buttonOK.y;
				addChild(buttonCacel);
				buttonCacel.addEventListener(MouseEvent.CLICK, onButtonOKClick);
			}
		}
		
		private function onButtonOKClick(event:MouseEvent):void
		{
			close();
		}
		
		public function close():void
        {
        	if (this.parent != null)
        	{
        		this.parent.removeChild(this);
        	}
        }
        
	}
}